package com.lili.core.jdbc.datasource.factory;

import javax.sql.DataSource;

import org.springframework.beans.factory.FactoryBean;

import com.lili.core.bridge.ModuleRegistry;
import com.lili.core.jdbc.datasource.DataSourceEnum;
import com.lili.core.jdbc.datasource.IDataSourceModule;

@SuppressWarnings("unchecked")
public class DataSourceFactoryBean implements FactoryBean{
    private DataSourceEnum definition;

    public DataSourceEnum getDefinition() {
        return definition;
    }

    public void setDefinition(DataSourceEnum definition) {
        this.definition = definition;
    }

    @Override
    public Object getObject() throws Exception {
          IDataSourceModule module = ModuleRegistry.getInstance().getModule(IDataSourceModule.class);
            DataSource dataSource = module.getLocator().getDataSource(definition);
        return dataSource;
    }

    @Override
    public Class<?> getObjectType() {
        return DataSource.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }

}
